#include "event.h"
#include <stdio.h>

Event *event_create () {
    Event *e;
    e = g_new0 (Event, 1);
    return e;
}

int event_populate (Event *e,  gchar *host,  gchar *type,  gchar *source,  gchar *source_type, 
                                         gchar *target,  gchar *target_type) {
    g_snprintf (e->host, EVENT_STR_BUFSZ,"%s", host);
    g_snprintf (e->type,EVENT_STR_BUFSZ, "%s", type);
    g_snprintf (e->source, EVENT_STR_BUFSZ,"%s", source);
    g_snprintf (e->source_type, EVENT_STR_BUFSZ,"%s", source_type);
    g_snprintf (e->target, EVENT_STR_BUFSZ,"%s", target);
    g_snprintf (e->target_type, EVENT_STR_BUFSZ,"%s", target_type);
    return 0;
}

int event_copy (Event *from, Event *to) {
    g_snprintf (to->host, EVENT_STR_BUFSZ,"%s", from->host);
    g_snprintf (to->type, EVENT_STR_BUFSZ,"%s", from->type);
    g_snprintf (to->source, EVENT_STR_BUFSZ,"%s", from->source);
    g_snprintf (to->source_type,EVENT_STR_BUFSZ, "%s", from->source_type);
    g_snprintf (to->target, EVENT_STR_BUFSZ,"%s", from->target);
    g_snprintf (to->target_type, EVENT_STR_BUFSZ,"%s", from->target_type);
    return 0;
}

int event_clear (Event *e) {
    e->host[0] = '\0';
    e->type[0] = '\0';
    e->source[0] = '\0';
    e->source_type[0] = '\0';
    e->target[0] = '\0';
    e->target_type[0] = '\0';
    e->remove_target = FALSE;
    return 0;    
}

int event_destructor (Event *e) {
    event_clear (e);
    g_free (e);
}

int event_output (Event *e, FILE* out) {
    return  fprintf (out, "%s(%s) -> %s(%s) (host=%s,type=%s)\n",e->source,
                                 e->source_type, e->target, e->target_type, e->host, e->type);
}
